package com.xzc.java8.B_Stream.h_reduce;

import com.xzc.java8.B_Stream.g_find.Apple;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class CountTest {

    public static void main(String[] args) {
        List<Apple> list0 = new ArrayList<>();
        Apple a0 = new Apple("red");
        Apple a1 = new Apple("blue");
//        Apple a1 = new Apple("red");
//        Apple a2 = new Apple("yellow");
        Apple a2 = new Apple("red");
        Apple a3 = new Apple("red");
        list0.add(a0);
        list0.add(a1);
        list0.add(a2);
        list0.add(a3);

        Optional<Integer> out0 = list0.stream().filter(Apple::isRedApple).map(d -> 1).reduce(Integer::sum);
        out0.ifPresent(System.out::println);

        long out1 = list0.stream().filter(Apple::isRedApple).count();
        System.out.println(out1);
    }
}
